package com.group2.operations.mapper;

import com.group2.operations.model.ProcessState;
import org.apache.ibatis.annotations.*;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
@Mapper
public interface FlowMapper {

    /**
     * 插入流程状态的记录
     * @param processId 流程ID
     * @param state 状态描述
     * @param time 发生时间
     */
    @Insert("insert into `process-state`(id, state1, time1) values(#{processId}, #{state}, #{time})")
    void insertFlowState(@Param("processId") String processId, @Param("state") String state, @Param("time") Date time);

    /**
     * 通过流程Id查询流程所有的历史事件
     * @param processId
     * @return
     */
    @Select("select * from `process-state` where id = #{processId}")
    ProcessState queryHistoryByProcessId(String processId);

    /**
     * 更新签订合同事件的状态
     * @param processId 流程ID
     * @param state5 状态5
     * @param time5 时间5
     */
    @Update("update `process-state` set state5=#{state5}, time5=#{time5} where id=#{id}")
    void updateSignProcessState(@Param("id") String processId, @Param("state5") String state5, @Param("time5") Date time5);
}
